<template>
	<view class="AuditOperation dis-cen">
		<view class="operation">
			<u-button type="primary" @click="params.remarks='',adminShow=true" :plain="true"
				:customStyle="{height: '90rpx',margin: 0, borderRadius: '12rpx'}" color="#D1D1D1">
				<text class="color3 font-weight-600 size-32">拒绝通过</text>
			</u-button>
			<u-button type="primary" @click="onShowModal" :disabled="disabled"
				:customStyle="{height: '90rpx',margin: 0, borderRadius: '12rpx'}"
				color="linear-gradient( -90deg, #EB0000 0%, #FF4545 100%)">
				<text class="color-f font-weight-600 size-32">同意通过</text>
			</u-button>
		</view>
		<u-popup :show="adminShow" :round="24" @close="adminShow=false">
			<view class="popup-title por dis border-bottom">
				<text class="color0 size-32">拒绝原因</text>
				<text class="iconfont icon-guanbi poa size-40 color3" @click="adminShow=false"></text>
			</view>
			<view class="popup">
				<view class="color3 size-30">拒绝原因</view>
				<view class="textarea-wai por">
					<textarea class="textarea" :maxlength="50" v-model="params.remarks" auto-height
						placeholder="请输入拒绝通过的原因" placeholder-class="color9" />
					<view class="textarea-poa poa size-28 color9">{{params.remarks.length || 0}}/50</view>
				</view>
				<u-button type="primary" :disabled="disabled" @click="onRejectReason(2)"
					:customStyle="{width: '702rpx',height: '90rpx ',margin: '0 auto', borderRadius: '12rpx'}"
					color="#EB0000">
					<text class="color-f font-weight-600 size-32">确认并拒绝</text>
				</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { UpdateStatus, Examine } from "@/api/index"
	export default {
		props: {
			types: {
				type: Number,
				default: 1 // 1=身份详情 2=提现列表
			},
			auditId: {
				type: Number,
				default: 0,
			}
		},
		data() {
			return {
				adminShow: false,
				params: {
					id: 0, // 	申请id
					status: 1, // 审核状态 1.通过 2.驳回
					remarks: '', // 拒绝原因
				},
				disabled: false
			}
		},
		methods: {
			// onRejectReason() {
			// 	this.$emit('rejectReason')
			// },
			// 二次确认
			onShowModal() {
				const _this = this
				uni.showModal({
					content: '确认已仔细核对提交资料，符合通过流程吗？',
					success: function(res) {
						if (res.confirm) {
							_this.onRejectReason(1)
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 拒绝/同意
			onRejectReason(index) {
				this.params.status = index
				if (!this.params.remarks && index == 2) {
					uni.$u.toast('请输入拒绝原因', 2000)
					return
				}
				this.postUpdateStatus()
			},
			// 操作审核
			async postUpdateStatus() {
				this.disabled = true
				let { params } = this
				params.id = this.auditId
				let paramsData = {}
				if (this.types == 2) {
					paramsData = {
						wighdrawId: this.auditId,
						status: params.status,
						explains: params.remarks
					}
				}
				const { code, data } = this.types == 1 ? await UpdateStatus(this.params) : await Examine(paramsData)
				if (code == '200') {
					this.adminShow = false
					this.$emit('agree')
				} else this.disabled = false
			},
		}
	}
</script>

<style lang="scss">
	.AuditOperation {
		.operation {
			width: 100%;
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			box-sizing: border-box;
			grid-gap: 24rpx;
		}

		// 弹窗
		.popup-title {
			height: 110rpx;

			.icon-guanbi {
				right: 24rpx;
			}
		}

		.popup {
			padding: 36rpx 24rpx 44rpx;

			// 文本域
			.textarea {
				width: 100%;
				margin: 28rpx 0 48rpx;
				height: 192rpx !important;
				background: #F6F6F6;
				border-radius: 10rpx;
				padding: 24rpx;
				box-sizing: border-box;
				color: #000000;
				font-size: 28rpx;
			}

			.textarea-poa {
				right: 24rpx;
				bottom: 24rpx;
			}
		}
	}
</style>